// pages/tabBar/my/my.js
const http = require("../../../utils/httpUtils");
const app = getApp()
Page({
    data: {
        height: app.globalData.height
    },
    onLoad: function(options) {
        // this.getInfoReques()
    },
    onShow() {
        // 每次进入新页面的刷新数据
        this.getInfoReques()
    },
    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {
        this.getInfoReques()
    },
    helpFeedback() { //帮助反馈
        wx.navigateTo({
            url: '/pages/tabBar/my/helpFeedback/helpFeedback',
        })
    },
    setting() { //设置
        wx.navigateTo({
            url: '/pages/tabBar/my/set/set',
        })
    },
    mycomments() { //我的评论
        wx.navigateTo({
            url: '/pages/tabBar/my/mycomments/mycomments',
        })
    },
    myzan() { // 我赞过的文章
        wx.navigateTo({
            url: '/pages/tabBar/my/myzan/myzan',
        })
    },
    cart() { // 购物车
        wx.navigateTo({
            url: '/pages/shop-cart/index',
        })
    },
    myFollow() { //我的关注
        wx.navigateTo({
            url: '/pages/tabBar/my/myFollow/index',
        })
    },
    myFans() { //我的粉丝
        wx.navigateTo({
            url: '/pages/tabBar/my/myFans/index',
        })
    },
    getInfoReques() { //获取用户信息
        var that = this;
        http._headerGet('/api/user/getUserInfo', null, res => {
            // console.log(res.data);
            //如果没有登录，就去登录
            if (res.data.code == 1) {
                app.globalData.userInfo = res.data.data
                this.setData({
                    userInfo: res.data.data
                })
                wx.setStorage({ // 存储用户数据
                    key: 'userInfo',
                    data: res.data.data,
                })
                wx.stopPullDownRefresh()
            } else {
                wx.stopPullDownRefresh()
                wx.showModal({
                    title: '提示',
                    content: `个人信息${res.data.msg},是否去登录?`,
                    success: res => {
                        if (res.confirm) {
                            wx.reLaunch({
                                url: '/pages/public/login/login'
                            })
                        }
                    }
                })
            }
        })

    },
    share() { //分享操作菜单
        wx.showActionSheet({
            itemList: ['分享给微信好友', '保存图片海报'],
            success(res) {
                if (res.tapIndex == 0) {

                }
            },
            fail(res) {
                console.log(res.errMsg)
            }
        })
    },
    previewImage() { //预览头像大图
        wx.previewImage({
            current: this.data.userInfo.head_portrait,
            urls: [this.data.userInfo.head_portrait]
        })
    }
})